package com.xiumu.controller.blog;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xiumu.common.core.page.PageQuery;
import com.xiumu.common.core.result.ResultJSON;
import com.xiumu.pojo.blog.entity.BlogTag;
import com.xiumu.pojo.blog.query.BlogTagQuery;
import com.xiumu.service.blog.BlogTagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 文章标签 Controller
 *
 * @author XiuMu
 * @Date 2023-01-30 14:22:50
 */
@RestController
public class BlogTagController {

    @Autowired
    private BlogTagService blogTagService;

    /**
     * 分页查询
     * 可传递查询参数，按照某些字段分页查询
     *
     * @param pageQuery 分页条件，查询参数
     * @return
     */
    @PostMapping("/page/blogTag")
    public ResultJSON<Page<BlogTag>> page(@RequestBody PageQuery<BlogTagQuery, BlogTag> pageQuery) {
        return ResultJSON.querySuccess(blogTagService.listPage(pageQuery));
    }

    /**
     * 查询全部
     * 可传递查询参数，按照某些字段查询
     *
     * @param blogTag 查询条件
     * @return
     */
    @GetMapping("/blogTag")
    public ResultJSON<List<BlogTag>> list(BlogTagQuery blogTag) {
        List<BlogTag> blogTagList = blogTagService.listByBlogTag(blogTag);
        return ResultJSON.querySuccess(blogTagService.listByBlogTag(blogTag));
    }

    /**
     * 创建 blogTag
     *
     * @param tagName 标签名称
     * @return
     */
    @PostMapping("/blogTag/{tagName}")
    public ResultJSON<Boolean> create(@PathVariable String tagName) {
        return ResultJSON.createSuccess(blogTagService.create(tagName));
    }
}
